package com.ihr360.attendance;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.ihr360.common.DateRange;
import com.ihr360.commons.lang.CollectionUtils;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 * 只保存实际有数据的人的列表
 * 考勤月报表
 * 出勤天数
 * 平时加班(小时)
 * 周末加班(小时)
 * 法定日加班(小时)
 * 加班合计(小时)
 * 折算加班时数(小时)
 * 病假(天)
 * 事假(天)
 * 年假(天)
 * 休假合计(天)
 */
@JsonIgnoreProperties(ignoreUnknown = true)
public class AttendancePeriodReport implements Serializable {
    private String staffId;
    private String staffName;
    private int year;
    private int month;
    private DateRange dateRange;

    private AttendanceReportFixedPart fixedPart;

    private Map<String, Double> flexPart;

    public static AttendancePeriodReport build(String staffId, String staffName, int year, int month, DateRange dateRange, Map<String, Double> items) {
        return new AttendancePeriodReport(staffId, staffName, year, month, dateRange, items);
    }

    public AttendancePeriodReport() {
    }

    public AttendancePeriodReport(String staffId, String staffName, int year, int month, DateRange dateRange, Map<String, Double> flexPart) {
        this.staffId = staffId;
        this.year = year;
        this.month = month;
        this.dateRange = dateRange;
        this.flexPart = flexPart;
        this.staffName = staffName;
    }


    public String getStaffId() {
        return staffId;
    }

    public void setStaffId(String staffId) {
        this.staffId = staffId;
    }

    public int getYear() {
        return year;
    }

    public void setYear(int year) {
        this.year = year;
    }

    public int getMonth() {
        return month;
    }

    public void setMonth(int month) {
        this.month = month;
    }

    public DateRange getDateRange() {
        return dateRange;
    }

    public void setDateRange(DateRange dateRange) {
        this.dateRange = dateRange;
    }

    public Map<String, Double> getFlexPart() {
        return flexPart;
    }

    public void setFlexPart(Map<String, Double> flexPart) {
        this.flexPart = flexPart;
    }

    public AttendanceReportFixedPart getFixedPart() {
        return fixedPart;
    }

    public void setFixedPart(AttendanceReportFixedPart fixedPart) {
        this.fixedPart = fixedPart;
    }

    public String getStaffName() {
        return staffName;
    }

    public void setStaffName(String staffName) {
        this.staffName = staffName;
    }

    @JsonIgnoreProperties
    public Map<String, Double> toDynamicCells() {
        Map<String, Double> map;

        if (flexPart != null && CollectionUtils.isNotEmpty(flexPart)) {
            map = new HashMap<>(flexPart);
        } else {
            map = new HashMap<>(20);
        }
        if (fixedPart != null) {
            /**
             * 实际出勤天数
             */
            map.put(AttendanceReportFixedPart.Field.WORKING_DAYS, fixedPart.getWorkingdays());
            /**
             * 应出勤天数（不包含法定节假日）
             */
            map.put(AttendanceReportFixedPart.Field.SUPPOSED_WORKING_DAYS, fixedPart.getSupposedworkingdays());

            /**
             * 法定计薪天数（标准工作天数，21.75）
             */
            map.put(AttendanceReportFixedPart.Field.PAID_DAYS, fixedPart.getPaiddays());

            /**
             * 缺勤天数
             */
            map.put(AttendanceReportFixedPart.Field.NON_WORKING_DAYS, fixedPart.getNonWorkingDays());

            /**
             * 非在职计薪天数
             */
            map.put(AttendanceReportFixedPart.Field.ABSENCE_FROM_DUTY_DAYS, fixedPart.getAbsencefromdutydays());

            /**
             * 平日加班小时-标准
             */
            map.put(AttendanceReportFixedPart.Field.OT_HOURS_150, fixedPart.getOthours150());
            /**
             * 周末加班小时-标准
             */
            map.put(AttendanceReportFixedPart.Field.OT_HOURS_200, fixedPart.getOthours200());
            /**
             * 节假日加班小时-标准
             */
            map.put(AttendanceReportFixedPart.Field.OT_HOURS_300, fixedPart.getOthours300());

            /**
             * 工作日加班累计（小时）
             */
            map.put(AttendanceReportFixedPart.Field.WORKINGDAY_OVERTIME_CAL, fixedPart.getWorkingdayovertimecal());

            /**
             * 休息日加班累计（小时）
             */
            map.put(AttendanceReportFixedPart.Field.RESTDAY_OVERTIME_CAL, fixedPart.getRestdayovertimecal());

            /**
             * 节假日加班累计（小时）
             */
            map.put(AttendanceReportFixedPart.Field.HOLIDAY_OVERTIME_CAL, fixedPart.getHolidayovertimecal());

            /**
             * 扣薪病假天数
             */
            map.put(AttendanceReportFixedPart.Field.SICK_LEAVE_COUNT, fixedPart.getSickleavecnt());

            /**
             * 全薪病假时长
             */
            //map.put(AttendanceReportFixedPart.Field.PAY_SICK_LEAVE_COUNT, fixedPart.getSickleavecnt());
            /**
             * 事假天数
             */
            map.put(AttendanceReportFixedPart.Field.UNPAID_LEAVE_COUNT, fixedPart.getUnpaidleavecnt());
            /**
             * 产假天数
             */
            map.put(AttendanceReportFixedPart.Field.MATERNITY_COUNT, fixedPart.getMaternitycnt());


            /**
             * 工时调整-综合
             */
            map.put(AttendanceReportFixedPart.Field.SYNTHETICAL_ADJUST, fixedPart.getSyntheticaladjust());

            /**
             * 节假日加班小时-综合
             */
            map.put(AttendanceReportFixedPart.Field.SYNTHETICAL_OTHOURS_300, fixedPart.getSyntheticalothours300());
            /**
             * 月工作日工时-综合
             */
            map.put(AttendanceReportFixedPart.Field.SYNTHETICAL_WORKHOURMONTH, fixedPart.getSyntheticalworkhourmonth());
            /**
             * 季工作日工时-综合
             */
            map.put(AttendanceReportFixedPart.Field.SYNTHETICAL_WORKHOURQUARTER, fixedPart.getSyntheticalworkhourquarter());
            /**
             * 年工作日工时-综合
             */
            map.put(AttendanceReportFixedPart.Field.SYNTHETICAL_WORKHOURYEAR, fixedPart.getSyntheticalworkhouryear());
            /**
             * 年假时长
             */
            map.put(AttendanceReportFixedPart.Field.ANNUAL_LEAVETIME, fixedPart.getAnnualleavetime());
            /**
             * 调休时长
             */
            map.put(AttendanceReportFixedPart.Field.REST_HOURS, fixedPart.getResthours());
            /**
             * 迟到次数
             */
            map.put(AttendanceReportFixedPart.Field.LATE_ARRIVALS, fixedPart.getLatearrivals());
            /**
             * 早退次数
             */
            map.put(AttendanceReportFixedPart.Field.RETURN_EARLY, fixedPart.getReturnearly());

            /**
             * 签到遗漏次数（原始次数）
             */
            map.put(AttendanceReportFixedPart.Field.SIGN_IN_MISS, fixedPart.getSigninmiss());
            /**
             * 签退遗漏次数（原始次数）
             */
            map.put(AttendanceReportFixedPart.Field.SIGN_OUT_MISS, fixedPart.getSignoutmiss());
            /**
             * 累计迟到分钟数
             */
            map.put(AttendanceReportFixedPart.Field.LATE_MINUTES, fixedPart.getLateminutes());

            /**
             *  累计早退分钟数
             * */
            map.put(AttendanceReportFixedPart.Field.EARLY_MINUTES, fixedPart.getEarlyminutes());

            /**
             *  缺勤次数
             * */
            map.put(AttendanceReportFixedPart.Field.ABSENCE_FROM_DUTY, fixedPart.getAbsencefromduty());
        }
        return map;
    }
}